from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.orm import declarative_base
#import inspect

#engine: 
#    responsible for connecting to the database and executing SQL commands.
# dialect 方言; postgresql为SQL的方言?
# "dialect+driver://username:password@host:port/database"
POSTGRESQL_DATABASE_URL ="postgresql+psycopg2://fyfdev:123456@127.0.0.1:5432/fyfdevdb"
# echo=True,输出"引擎"做了哪些操作.
engine = create_engine(POSTGRESQL_DATABASE_URL, echo=True)

# declare a mapping
Database_Modelfyfdevdb = declarative_base()
#print(Database_Modelfyfdevdb, inspect.getmro(Database_Modelfyfdevdb))
#print(type(Database_Modelfyfdevdb))

# a single table name users
class Users(Database_Modelfyfdevdb):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True)
    name = Column(String)
#print(Users)
#print(type(Users), inspect.getmro(Users))


temp = Database_Modelfyfdevdb.metadata
#print(temp, type(temp), type.__class__, type.__bases__)
#print(dir(temp))
#print(temp.tables)
# 数据库(database)模式(schema)的元信息：表、列、索引和外键等。
#Database_Modelfyfdevdb.metadata.create_all(engine)

